home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / PixMapToPICT.Old.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-02  |  1.8 KB  |  63 lines  |  [TEXT/KAHL]

  1. /*
  2. PixMapToPICT.c
  3. Saves a section of a PixMap as a PICT file.
  4.  
  5. HISTORY:
  6. 9/28/93    mike schechter wrote it, based in part on PixMapToPostScript.c
  7. 9/29/93    dgp polished it, substituting a GWorld for a CPort, so that a
  8.             custom GDevice will be used, instead of whatever is current,
  9.             so we'll preserve our current pixel size and color table.
  10. */
  11.  
  12. #include "VideoToolbox.h"
  13.  
  14. void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  15.     ,int pixelSize,ColorTable **cTable)
  16. {
  17.     FILE *file;
  18.     long buffer[128],n,value;
  19.     short error;
  20.     PicHandle pic;
  21.     CGrafPtr oldPort;
  22.     GDHandle oldDevice;
  23.     int i;
  24.     GWorldPtr world;
  25.     
  26.     Gestalt(gestaltQuickdrawVersion,&value);
  27.     if(value<gestalt32BitQD)
  28.         PrintfExit("Sorry. PixMapToPICT requires 32-bit QuickDraw.\n");
  29.  
  30. /* draw pixmap into a Picture */
  31.     GetGWorld(&oldPort,&oldDevice);
  32.     error=NewGWorld(&world,(**pm).pixelSize,rectPtr,(**pm).pmTable,NULL,0);
  33.     if(error)PrintfExit("PixMapToPICT: NewGWorld error %d.\n",error);
  34.     SetGWorld(world,NULL);
  35.     LockPixels(world->portPixMap);
  36.     ClipRect(rectPtr);
  37.     pic=OpenPicture(rectPtr);
  38.     EraseRect(rectPtr);
  39.     CopyBits((BitMap *)*pm,(BitMap *)*world->portPixMap
  40.         ,rectPtr,rectPtr,srcCopy,NULL);
  41.     ClosePicture();
  42.     SetGWorld(oldPort,oldDevice);
  43.     DisposeGWorld(world);
  44.     if(EmptyRect(&(*pic)->picFrame))PrintfExit("PixMapToPICT: out of memory.\n");
  45.     
  46. /* save Picture to a file */
  47.     file=fopen(filename,"wb");
  48.     if(file==NULL)PrintfExit("PixMapToPICT: Error in opening file \"%s\".\n"
  49.         ,filename);
  50.     /* zero 512-byte header */
  51.     for(i=0;i<128;i++) buffer[i]=0;
  52.     if(128!=fwrite(buffer,4,128,file))
  53.         PrintfExit("PixMapToPICT: Error writing header of file \"%s\".\n",filename);
  54.     n=GetHandleSize((Handle)pic);
  55.     if(n&1 !=0)n++;    /* pad to even length */
  56.     if(n!=fwrite(*pic,1,n,file))
  57.         PrintfExit("PixMapToPICT: Error writing file \"%s\"\n",filename);
  58.     fclose(file);
  59.     SetFileInfo(filename,'PICT','ttxt');
  60.     KillPicture(pic);
  61. }
  62.  
  63.